package com.heihei.web.filter;


import javax.servlet.*;
import java.io.IOException;
import java.util.Date;

/**
 *  fliter过滤器测试
 *  filter无法获取当前是哪个控制器的哪个接口，如需获取该详情，建议使用拦截器  Interceptor
 *
 * @version 1.0
 * @since JDK1.8
 * @author duanhengfei
 * @date 2021年03月27日 16:01:02
 */
//@Component
public class TimeFilter implements Filter {


	@Override
	public void destroy() {
		System.out.println("time filter destroy");
	}


	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		System.out.println("time filter start");
		long start = new Date().getTime();
		chain.doFilter(request, response);
		System.out.println("time filter 耗时:"+ (new Date().getTime() - start));
		System.out.println("time filter finish");
	}


	@Override
	public void init(FilterConfig arg0) throws ServletException {
		System.out.println("time filter init");
	}

}
